import Request from "@/common/utils/request/index";
import { UpdateProductDto } from "@/types/model/product/dtos/category.dto";
import { UpdateVariantDto } from "@/types/model/product/dtos/product.dto";
import { PageList } from "@/types/model/pageList.model";
import { Product } from "@/types/model/product/vos/product.vo";
import { SearchProductsDto } from "@/types/model/product/dtos/searchProducts.dto";
import { SearchProductVO } from "@/types/model/product/vos/searchProducts.vo";

enum Api {
  CreateProduct = "/jeecgboot/posProduct/createProduct",
  GetProducts = "/jeecgboot/posProduct/list",
  GetSingleProducts = "/jeecgboot/posProduct/singleList",
  GetProductById = "/jeecgboot/posProduct/getProductById",
  GetVariantsList = "/jeecgboot/posVariants/list",
  GetVariantsByProductId = "/jeecgboot/posVariants/getVariantsByProductId",
  GetVariantsByPage = "/jeecgboot/posVariants/getVariantsByPage",
  GetVariantForCheckList = "/jeecgboot/posVariants/getVariantForCheckList",
  GetTradeinVariant = "/jeecgboot/posVariants/getTradeinVariant",
  UpdateProduct = "/jeecgboot/posProduct/updateProduct",
  UpdateVariantById = "/jeecgboot/posVariants/updateVariantById",
  SearchProducts = "/jeecgboot/posProduct/searchProducts",
  SearchEs = "/jeecgboot/posProduct/searchEs",
}

export const searchProducts = (params: SearchProductsDto) => {
  return Request.getInstance().send<PageList<SearchProductVO>>({
    url: Api.SearchProducts,
    method: "GET",
    params: params,
  });
};

export const createProduct = (params: any) => {
  return Request.getInstance().send<any>({
    url: Api.CreateProduct,
    method: "POST",
    data: params,
  });
};

export const updateProduct = (params: UpdateProductDto) => {
  return Request.getInstance().send<any>({
    url: Api.UpdateProduct,
    method: "POST",
    data: params,
  });
};

export const getProducts = (params: any) => {
  return Request.getInstance().send<PageList<Product>>({
    url: Api.GetProducts,
    method: "GET",
    params,
  });
};

export const getSingleProducts = (params: any) => {
  return Request.getInstance().send<any>({
    url: Api.GetSingleProducts,
    method: "GET",
    params,
  });
};

export const getProductById = (productId: string) => {
  return Request.getInstance().send<any>({
    url: Api.GetProductById,
    method: "GET",
    params: {
      id: productId,
    },
  });
};

export const getVariantsList = (params: any) => {
  return Request.getInstance().send<any>({
    url: Api.GetVariantsList,
    method: "GET",
    params,
  });
};

export const getVariantsByProductId = (productId: string) => {
  return Request.getInstance().send<any>({
    url: Api.GetVariantsByProductId,
    method: "GET",
    params: {
      productId,
    },
  });
};

export const getTradeinVariant = (params: any) => {
  return Request.getInstance().send<any>({
    url: Api.GetTradeinVariant,
    method: "POST",
    data: params,
  });
};

export const getVariantsByPage = (params: any) => {
  return Request.getInstance().send<PageList<any>>({
    url: Api.GetVariantsByPage,
    method: "POST",
    data: params,
  });
};

export const getVariantForCheckList = (params: any) => {
  return Request.getInstance().send<any>({
    url: Api.GetVariantForCheckList,
    method: "GET",
    params,
  });
};

export const updateVariantById = (params: UpdateVariantDto) => {
  return Request.getInstance().send<any>({
    url: Api.UpdateVariantById,
    method: "POST",
    data: params,
  });
};

export const searchEs = (params: any) => {
  return Request.getInstance().send<any>({
    url: Api.SearchEs,
    method: "GET",
    params,
  });
};
